import { _analyse } from '../../common/api/test'
const app = getApp()
Page({
  data: {
    sortnum: null,
    testid: null,
    questid: null,
    detail: null
  },
  analyse () {
    app.loading('加载中')
    let memberid = wx.getStorageSync('memberid')
    _analyse(this.data.questid, this.data.testid, memberid).then(res => {
      wx.hideLoading()
      if (res.data.IsSuccess) {
        let detail = res.data.Data
        detail.CheckList = detail.CheckList.map(item => {
          item.checked = detail.MemberAns.includes(item.Key) ||detail.Ans.includes(item.Key)
          item.className = detail.Ans.includes(item.Key) ? 'right' :  detail.MemberAns.includes(item.Key) ? 'wrong' : ''
          return item
        })
        detail.single = detail.AnsType.includes('单选')
        // detail.MemberAns = detail.MemberAns.replace(/\,/g, '、')
        this.setData({
          detail
        })
      }
    }).catch(err => {
      console.log(err)
      wx.hideLoading()
    })
  },
  onLoad (options) {
    this.data.testid = options.testid
    this.data.questid = options.questid
    this.data.sortnum = options.sortnum
    this.setData({
      testid: this.data.testid,
      questid: this.data.questid,
      sortnum: this.data.sortnum
    })
  },
  onReady () {},
  onShow () {
    if (app.store.userinfo) {
      this.data.userinfo = app.store.userinfo
      this.analyse()
    } else {
      app.loading('加载中')
      app.launch().then(res => {
        wx.hideLoading()
        console.log(res)
        this.data.userinfo = res
        this.analyse()
      }).catch(err => {
        wx.hideLoading()
        console.log(err)
      })
    }
  },
  onHide () {},
  onUnload () {},
  onPullDownRefresh () {},
  onReachBottom () {},
  onShareAppMessage () {}
})